
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>循环依赖是什么 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>循环依赖是什么 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">什么是Spring中的循环依赖？它通常在哪种情况下出现？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">循环依赖指的是在对象的创建过程中，出现两个或多个对象互相依赖的情况。这种情况在Spring中使用依赖注入（DI）时比较常见。</div>
          </div>
          <div class="card-source">来源: 循环依赖</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">文档中描述了哪两种类型的循环依赖？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中描述了两种类型：1. 构造器循环依赖，发生在使用构造函数注入时；2. Setter循环依赖，发生在使用setter方法注入时。</div>
          </div>
          <div class="card-source">来源: 1. 循环依赖的定义</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">为什么Spring容器无法解决构造器循环依赖问题？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">因为在构造器注入过程中，Spring必须完全构造Bean实例才能满足所有依赖。在循环依赖的情况下，Bean之间相互等待对方的创建，导致无法完成实例化，Spring最终会抛出 `BeanCurrentlyInCreationException` 异常。</div>
          </div>
          <div class="card-source">来源: 2. 处理循环依赖的机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Spring容器是如何解决Setter注入方式的循环依赖的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Spring通过三级缓存机制来解决setter循环依赖。它首先创建一个Bean的实例（但未完成注入）并放入缓存，然后在设置属性时，如果发现依赖了其他尚未完成的Bean，它会从缓存中获取那个正在创建中的Bean的引用，从而打破循环。</div>
          </div>
          <div class="card-source">来源: 2. 处理循环依赖的机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在解决循环依赖问题时，`@Lazy`注解起到了什么作用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`@Lazy`注解可以延迟Bean的初始化，使得Bean的创建只在它第一次被使用时才发生。这样可以避免在容器启动和Bean实例化阶段立即创建所有依赖，从而打破循环依赖。</div>
          </div>
          <div class="card-source">来源: 3. 循环依赖的解决方案</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">除了使用`@Lazy`注解，文档还提到了哪些解决循环依赖的策略？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档还提到了两种策略：1. 重构设计，例如将互相依赖的Bean抽象成接口来解耦；2. 使用方法注入，将依赖注入推迟到Bean实例化之后的阶段。</div>
          </div>
          <div class="card-source">来源: 3. 循环依赖的解决方案</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
